package a09_贪心算法;

/**
 * <p>
 * a03_摆动序列复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/3
 */
public class a03_摆动序列复习3 {
    public int wiggleMaxLength(int[] nums) {
        int result = 1;

        int prevDiff = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            int nextDiff = nums[i+1] - nums[i];
            if((prevDiff <= 0 && nextDiff > 0) || (prevDiff >= 0 && nextDiff < 0)){
                result++;
                prevDiff = nextDiff;
            }
        }

        return result;
    }
}
